var playr;
layui.config({
    base: '../lib/layui/lay/modules/' //配置 layui 第三方扩展组件存放的基础目录
}).extend({
    locationX: 'locationX',
    location: 'location'
});
layui.use(['element','table','form','layer','laydate','location'], function(){
    var table = layui.table,
    form = layui.form,
    $ = layui.jquery,
    laydate = layui.laydate,
    layer = layui.layer;
    let location = layui.location;

    loadCommunityList();

    loadTypeList();

    function loadCommunityList() {
        $.get('/cdysylives/secret/queryCommunityList', {}, function (result) {
            if(result != null){
                if(result.data != null){
                    var $opt_html = "<option value=''>请选择社区</option>";
                    $.each(result.data, function (index, item) {
                        $opt_html += "<option value='" + item.id + "'>" + item.name + "</option>";
                    });
                    $("#searchCommunityId").empty().append($opt_html);
                    $("#communityId").empty().append($opt_html);
                    form.render('select');
                }
            }
        });
    }

    function loadTypeList() {
        $.get('/cdysylives/monitor/listDeviceType', {}, function (result) {
            if(result != null){
                if(result.data != null){
                    var $opt_html = "<option value=''>请选择类型</option>";
                    $.each(result.data, function (index, item) {
                        $opt_html += "<option value='" + item + "'>" + item + "</option>";
                    });
                    $("#deviceType").empty().append($opt_html);
                    form.render('select');
                }
            }
        });
    }

    form.on('select(searchCommunityId)',function (data) {
        loadBuildingList(data.value,"searchBuildingId","");
    });

    form.on('select(communityId)',function (data) {
        loadBuildingList(data.value,"buildingId","");
    });

    function loadBuildingList(communityId,eleId,val){
        $.get('/cdysylives/monitor/queryBuildingList', {communityId:communityId}, function (result) {
            if(result != null){
                if(result.data != null){
                    var $opt_html = "<option value=''>请选择楼栋</option>";
                    $.each(result.data, function (index, item) {
                        $opt_html += "<option value='" + item.id + "'>" + item.name + "</option>";
                    });
                    $("#"+eleId).empty().append($opt_html);
                    if(val){
                        $("#"+eleId).val(val);
                    }
                    form.render('select');
                }
            }
        });
    }

    table.render({
        elem: '#deviceRecordTable'
        ,url:'/cdysylives/monitor/list'
        ,title: '设备列表'
        ,method: 'get'
        ,where: {}
        ,cols: [[
            {type: 'checkbox'},
            {field: 'xh',type:'numbers', title: '序号',}
            ,{field:'communityName', title:'社区名称',align:'center'}
            ,{field:'buildingName', title:'楼栋名称',align:'center'}
            ,{field:'deviceName', title:'设备名称',align:'center'}
            ,{field:'deviceType', title:'设备类型',align:'center'}
            ,{field:'deviceSerial', title:'设备序列号',align:'center'}
            ,{field: 'installType', title: '安装类型', align:'center',templet: function (d) {
                    return parseInstall(d.installType);
                }}
            ,{field:'address', title:'设备地址',align:'center'}
            ,{field: 'deviceStatus', title: '在线状态', align:'center',templet: function (d) {
                    return parseOnOffStatus(d.deviceStatus);
                }}
            ,{field: 'isEnabled', title: '启用状态', align:'center',templet: function (d) {
                    return parseStatus(d.isEnabled);
                }}
            , {field: 'right', title: '操作', align:'center',width:250,templet:function(data){
                    return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>' +
                        '<a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>' +
                        '<a class="layui-btn layui-btn-xs" lay-event="live">直播</a>' +
                        '<a class="layui-btn layui-btn-xs" lay-event="playback">回放</a>' +
                        '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                }
            }
        ]]
        ,page: true
    });

    // 自己维护初始化标注。这里给的是成都市政府
    var locationData = {lng:104.07253,lat:30.579126};
    location.render("#locationBtn1",{
        type:1,
        apiType: "baiduMap",
        coordinate: "baiduMap",
        mapType: 2,
        zoom: 15,
        title: '区域定位',
        init: function(){
            let longitude = $("#longitude").val();
            let latitude = $("#latitude").val();
            let lng = longitude ? longitude : locationData.lng;
            let lat = latitude ? latitude : locationData.lat;
            return {longitude: lng,latitude: lat};
        },
        success: function (data) { //只有经纬度
            $("#longitude").val(data.lng);
            $("#latitude").val(data.lat);
            showPosition(data);
        }
    });

    function showPosition(data){
        var url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=ltGX9ap4n4tYvEjYuNTNC76ZamxX7e5s&output=json&coordtype=wgs84ll&location="+data.lat+","+data.lng;
        $.ajax({
            type:  "GET" ,
            dataType:  "jsonp" ,
            url: url,
            beforeSend: function (){
            },
            success:  function  (json) {
                console.log(json);
                if(json.status === 0){
                    // $("#province").val(json.result.province);
                    // $("#city").val(json.result.city);
                    // $("#district").val(json.result.district);
                    $("#address").val(json.result.formatted_address);
                }
            },
            error:  function  (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg("地址位置获取失败",{icon:5});
            }
        });
    }

    //批量启用
    form.on('submit(enable)',function(obj){
        var checkStatus = table.checkStatus('deviceRecordTable');
        var	data = checkStatus.data;
        if(data.length === 0){
            layer.tips("请至少选择一条记录!",this);
            return false;
        }
        var idArr = [];
        data.forEach(item=>{
            idArr.push(item.id);
        });
        $.ajax({
            url: "/cdysylives/monitor/batchEnable",
            type: 'post',
            contentType: 'application/json',
            data: JSON.stringify(idArr),
            success: function (res) {
                if (res.success) {
                    layer.closeAll();
                    layer.msg(res.msg);
                    table.reload('deviceRecordTable',{page: {curr:1}});
                } else {
                    layer.msg(res.msg)
                }
            }
        });
        return false;
    });

    //批量禁用
    form.on('submit(disable)',function(obj){
        var checkStatus = table.checkStatus('deviceRecordTable');
        var	data = checkStatus.data;
        if(data.length === 0){
            layer.tips("请至少选择一条记录!",this);
            return false;
        }
        var idArr = [];
        data.forEach(item=>{
            idArr.push(item.id);
        });
        $.ajax({
            url: "/cdysylives/monitor/batchDisable",
            type: 'post',
            contentType: 'application/json',
            data: JSON.stringify(idArr),
            success: function (res) {
                if (res.success) {
                    layer.closeAll();
                    layer.msg(res.msg);
                    table.reload('deviceRecordTable',{page: {curr:1}});
                } else {
                    layer.msg(res.msg)
                }
            }
        });
        return false;
    });

    form.on('submit(saveDevice)',function(data){
        $("#saveDevice").attr("disabled", true);
        $("#saveDevice").attr("class", "layui-btn layui-btn-disabled");
        data.field.communityName = $("#communityId").find("option:selected").text();
        data.field.buildingName = $("#buildingId").find("option:selected").text();
        layer.load();
        $.ajax({
            type: 'post',
            url: '/cdysylives/monitor/saveOrUpdate',
            contentType: "application/json;charset=utf-8",
            dataType: 'json',
            data: JSON.stringify(data.field),
            success: function (res) {
                layer.msg(res.msg);
                setTimeout(function (){
                    layer.closeAll();
                },1000);
                $("#saveDevice").attr("disabled", false);
                $("#saveDevice").attr("class", "layui-btn");
                queryDevice();
            },
        });
        return false;
    });

    table.on('tool(deviceRecordTable)', function(obj){
        let data = obj.data;
        switch (obj.event){
            case 'edit':
                $("#operateDiv").show();
                $("#addCarForm").attr("disabled", false);
                $("#addCarForm").attr("class", "layui-btn");
                form.val("device_form", data);
                $("#id").val(data.id);
                loadBuildingList(data.communityId,"buildingId",data.buildingId);
                form.render();
                layer.open({
                    type: 1
                    , title: '编辑设备'
                    , shadeClose: true
                    , area: ['60%', '80%']
                    , btn: ['关闭']
                    , content: $('#updateDeviceDiv')
                });
                break;
            case 'detail':
                $("#operateDiv").hide();
                form.val("device_form", data);
                $("#id").val(data.id);
                loadBuildingList(data.communityId,"buildingId",data.buildingId);
                form.render();
                layer.open({
                    type: 1
                    , title: '设备详情'
                    , shadeClose: true
                    , area: ['60%', '80%']
                    , content: $('#updateDeviceDiv')
                });
                break;
            case 'live'://直播
                renderChannel(data.deviceSerial,data.communityId);
                $("#choosedCommunityId").val(data.communityId);
                layer.open({
                    type: 1
                    , title: '通道管理'
                    , shadeClose: true
                    , area: ['99%', '99%']
                    , content: $('#channelWindow')
                });
                break;
            case 'playback'://回放
                $.get('/cdysylives/monitor/listTask',{deviceId:data.id},function (res) {
                    if (res.success) {
                        if(res.data != null){
                            var $opt_html = "";
                            $.each(res.data, function (index, item) {
                                $opt_html += "<option value='" + item.taskId + "'>" + item.createTime + "</option>";
                            });
                            $("#taskId").empty().append($opt_html);
                            form.render('select');
                        }
                        renderFile($("#taskId").val(),data.communityId);
                    } else {
                        layer.msg(res.msg,{icon:5});
                    }
                    $("#deviceId").val(data.id);
                    $("#fileCommunityId").val(data.communityId);
                    layer.open({
                        type: 1
                        , title: '回放视频管理'
                        , shadeClose: true
                        , area: ['99%', '99%']
                        , content: $('#fileListWindow')
                    });
                });
                break;
            case 'del':
                layer.confirm('确定要删除吗?', {
                }, function(){
                    layer.load();
                    $.get('/cdysylives/monitor/delete',{id:data.id},function (res) {
                        layer.msg(res.msg,{
                            time:800,
                            end:function () {
                                queryDevice();
                                layer.closeAll();
                            }
                        });
                    });
                });
                break;
        }
    });

    form.on('select(taskId)',function (data) {
        reloadFileTable(data.value);
    });

    function reloadFileTable(taskId){
        var communityId = $("#fileCommunityId").val();
        table.reload('fileTable',{
            where: {"communityId":communityId,"taskId":taskId}});
    }

    $("#refreshFile").on("click",function () {
        $.get('/cdysylives/monitor/listTask',{deviceId:$("#deviceId").val()},function (res) {
            if (res.success) {
                if(res.data != null){
                    var $opt_html = "";
                    $.each(res.data, function (index, item) {
                        $opt_html += "<option value='" + item.taskId + "'>" + item.createTime + "</option>";
                    });
                    $("#taskId").empty().append($opt_html);
                    form.render('select');
                }
                renderFile($("#taskId").val(),$("#fileCommunityId").val());
            } else {
                layer.msg(res.msg,{icon:5});
            }
        });
    });

    function renderFile(taskId,communityId) {
        table.render({
            elem: '#fileTable'
            ,url:'/cdysylives/monitor/listFile'
            ,title: '视频文件列表'
            ,method: 'get'
            ,where: {"taskId":taskId,"communityId":communityId}
            ,cols: [[
                {field: 'xh',type:'numbers', title: '序号',}
                ,{field:'fileId', title:'文件ID',align:'center',hide:true}
                ,{field: 'fileType', title: '文件类型', align:'center',templet: function (d) {
                        return parseFileType(d.fileType);
                    }}
                ,{field: 'status', title: '文件状态', align:'center',templet: function (d) {
                        return parseFileStatus(d.status);
                    }}
                ,{field:'fileCount', title:'文件个数',align:'center'}
                ,{field:'fileSize', title:'文件大小(字节)',align:'center'}
                ,{field:'createTime', title:'创建时间',align:'center'}
                // ,{field:'duration', title:'转码时长(秒)',align:'center'}
                ,{field:'expireTime', title:'过期时间',align:'center'}
                // ,{field: 'storageType', title: '项目存储类型', align:'center',templet: function (d) {
                //         return parseStorageType(d.storageType);
                //     }}
                // ,{field:'lastTransferTime', title:'最后一次转换时间',align:'center'}
                // ,{field:'unfreezeTime', title:'解冻有效期',align:'center'}
                , {field: 'right', title: '操作', align:'center',templet:function(data){
                        return '<a class="layui-btn layui-btn-xs" lay-event="play">播放</a>';
                            // '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>';
                    }
                }
            ]]
            ,page:false
        });
    }

    table.on('tool(fileTable)', function(obj){
        let data = obj.data;
        switch (obj.event){
            case 'play':
                var videoHtml = "<video width='600' height='400' controls>"
                $.each(data.downloadUrls, function (index, item) {
                    videoHtml += "<source src='" + item + "' type='video/mp4'/>";
                });
                videoHtml += "</video>";
                layer.open({
                    type: 1,
                    shade: 0.8,
                    offset: 'auto',
                    area: ['50%', '80%'],
                    shadeClose: true,
                    scrollbar: false,
                    title: "视频回放",
                    content: videoHtml,
                    cancel: function () {
                    }
                });
                break;
            case 'delete':
                layer.confirm('确定要删除吗?', {
                }, function(){
                    let delLoad = layer.load();
                    var communityId = $("#fileCommunityId").val();
                    $.get('/cdysylives/monitor/deleteFile',{communityId:communityId,
                            fileId:data.fileId,projectId:data.projectId},function (res) {
                        layer.close(delLoad);
                        if(res.status == 200){
                            layer.msg(res.msg);
                            setTimeout(function (){
                                reloadFileTable($("#taskId").val());
                            },1000);
                        }else {
                            layer.msg(res.msg,{icon:5});
                        }
                    });
                });
                break;
        }
    });

    function renderChannel(deviceSerial,communityId) {
        table.render({
            elem: '#deviceChannelTable'
            ,url:'/cdysylives/monitor/listChannelByDevice'
            ,title: '通道列表'
            ,method: 'get'
            ,where: {"deviceSerial":deviceSerial,"communityId":communityId}
            ,cols: [[
                {field: 'xh',type:'numbers', title: '序号',}
                ,{field:'deviceSerial', title:'设备序列号',align:'center'}
                ,{field:'ipcSerial', title:'IPC序列号',align:'center'}
                ,{field:'channelNo', title:'通道号',align:'center'}
                ,{field:'deviceName', title:'设备名',align:'center'}
                ,{field:'localName', title:'设备上报名称',align:'center'}
                ,{field:'channelName', title:'通道名',align:'center'}
                ,{field: 'isEncrypt', title: '是否加密', align:'center',templet: function (d) {
                        return parseEncrypt(d.isEncrypt);
                    }}
                ,{field: 'videoLevel', title: '视频质量', align:'center',templet: function (d) {
                        return parseQuality(d.videoLevel);
                    }}
                ,{field: 'isAdd', title: '显示状态', align:'center',templet: function (d) {
                        return parseShow(d.isAdd);
                    }}
                ,{field: 'relatedIpc', title: '是否关联IPC', align:'center',templet: function (d) {
                        return parseRelatedIpc(d.relatedIpc);
                    }}
                ,{field:'devType', title:'camera设备类型',align:'center'}
                ,{field: 'picUrl', title: '图片地址', align:'center',templet:function (d) {
                        if(d.picUrl){
                            return '<img onclick="previewImg(this)" style="cursor: pointer" width="30" height="25" src="'+d.picUrl+'"/>';
                        }
                        return "";
                    }}
                , {field: 'right', title: '操作', align:'center',width:200,templet:function(data){
                        return '<a class="layui-btn layui-btn-xs" lay-event="monitor1">监控(流畅)</a>' +
                            '<a class="layui-btn layui-btn-xs" lay-event="monitor2">监控(高清)</a>';
                    }
                }
            ]]
            ,page:false
        });
    }

    table.on('tool(deviceChannelTable)', function(obj){
        let data = obj.data;
        switch (obj.event){
            case 'monitor1':
                getLiveAddress(data.deviceSerial,"2",data.channelNo);//流畅
                break;
            case 'monitor2':
                getLiveAddress(data.deviceSerial,"1",data.channelNo);//高清
                break;
        }
    });

    function getLiveAddress(deviceSerial,quality,channelNo) {
        var index = layer.load();
        var communityId = $("#choosedCommunityId").val();
        $.get("/cdysylives/monitor/getLiveAddress", {"communityId":communityId,"deviceSerial":deviceSerial,
            "quality":quality,"channelNo":channelNo}, function (result) {
            layer.close(index);
            if (result.resultCode === '000') {
                var urlToken = result.resultContent;
                if(urlToken){
                    $("#url").val(urlToken.url);
                    $("#accessToken").val(urlToken.token);
                    layer.open({
                        type: 1
                        , title: '监控模式'
                        , shadeClose: true
                        , area: ['99%', '99%']
                        , content: $('#monitorWindow'),
                        cancel: function(){
                            if(playr){
                                playr.stop();
                                $("#monitorWindow").find("#video-container-wrap").remove();
                            }
                        }
                    });
                }else {layer.msg("参数有误", {icon: 5});}
            } else {
                layer.msg(result.resultDesc, {icon: 5});
            }
        });
    }

    form.on('submit(refreshChannel)', function (data) {
        table.reload('deviceChannelTable',{page: {curr: 1}});
        return false;
    });

    form.on('submit(queryDevice)', function (data) {
        queryDevice(data.field);
        return false;
    });

    function queryDevice(fields){
        table.reload('deviceRecordTable', {
            where: fields
            , page: {
                curr: 1
            }
        });
    }

    $("#syncDevice").on('click',function () {
        let communityId = $("#searchCommunityId").val();
        if(!communityId){
            layer.msg("请先选择要同步的社区",{icon:5});
            return false;
        }
        table.render({
            elem: '#deviceTable'
            ,url:'/cdysylives/monitor/syncDevice'
            ,title: '设备列表'
            ,method: 'get'
            ,parseData: function(res) { //解析原始数据
                return {
                    "code": 0, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            ,where: {"communityId":communityId}
            ,cols: [[
                {type: 'checkbox'},
                {field: 'xh',type:'numbers', title: '序号',}
                ,{field:'deviceName', title:'设备名称',align:'center'}
                ,{field:'deviceSerial', title:'设备序列号',align:'center'}
                ,{field:'deviceType', title:'设备类型',align:'center'}
                ,{field: 'status', title: '在线状态', align:'center',templet: function (d) {
                        return parseOnOffStatus(d.status);
                    }}
                ,{field: 'defence', title: '布撤防状态', align:'center',templet: function (d) {
                        return parseDefence(d.defence);
                    }}
                ,{field:'deviceVersion', title:'设备版本号',align:'center'}
                ,{field:'addTime', title:'添加时间',align:'center',templet: function (d) {
                        return  d.addTime ? new Date(d.addTime*1).format('yyyy-MM-dd hh:mm:ss') : "";
                    }}
                ,{field:'updateTime', title:'更新时间',align:'center',templet: function (d) {
                        return  d.updateTime ? new Date(d.updateTime*1).format('yyyy-MM-dd hh:mm:ss') : "";
                    }}
                ,{field:'parentCategory', title:'父级分类',align:'center'}
            ]]
            ,page: false
        });
        $("#confirmCommunityId").val(communityId);
        layer.open({
            type: 1
            , title: '同步设备'
            , shadeClose: true
            , area: ['99%', '99%']
            , content: $('#confirmDeviceWindow')
        });
    });

    //批量确认同步设备
    form.on('submit(confirmSync)',function(obj){
        var deviceTable = table.checkStatus('deviceTable');
        var	data = deviceTable.data;
        if(data.length === 0){
            layer.tips("请至少选择一条记录!",this);
            return false;
        }
        var idArr = [];
        data.forEach(item=>{
            item.communityId = $("#confirmCommunityId").val();
            idArr.push(item);
        });
        $.ajax({
            url: "/cdysylives/monitor/batchConfirmDevice",
            type: 'post',
            contentType: 'application/json',
            data: JSON.stringify(idArr),
            success: function (res) {
                if (res.success) {
                    layer.closeAll();
                    layer.msg(res.msg);
                    table.reload('deviceRecordTable',{page: {curr:1}});
                } else {
                    layer.msg(res.msg)
                }
            }
        });
        return false;
    });

    $("#cancelAdd").on('click',function (){
        layer.closeAll();
    });

    $("#init").on('click',function (){
        var token = $("#accessToken").val();
        var url = $("#url").val();
        if(!token || !url){return layer.msg("获取播放地址失败",{icon:5})}
        let videoDiv = $("#monitorWindow").find("#video-container-wrap");
        if(videoDiv){
            videoDiv.remove();
        }
        $("#monitorWindow").append('<div id="video-container" style="width: 600px;"></div>');
        playr = new EZUIKit.EZUIKitPlayer({
            id: 'video-container', // 视频容器ID
            accessToken: token,
            url: url,
            template: 'pcLive', // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版; theme-可配置主题；
            plugin: ['talk'],                       // 加载插件，talk-对讲
            width: 600,
            height: 400,
        });
    });

    $("#play").on('click',function (){
        var playPromise = playr.play();
        playPromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#stop").on('click',function (){
        var stopPromise = playr.stop();
        stopPromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#getOSDTime").on('click',function (){
        var getOSDTimePromise = playr.getOSDTime();
        getOSDTimePromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#capturePicture").on('click',function (){
        var capturePicturePromise = playr.capturePicture();
        capturePicturePromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#openSound").on('click',function (){
        var openSoundPromise = playr.openSound();
        openSoundPromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#closeSound").on('click',function (){
        var closeSoundPromise = playr.closeSound();
        closeSoundPromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#startSave").on('click',function (){
        var startSavePromise = playr.startSave();
        startSavePromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#stopSave").on('click',function (){
        var stopSavePromise = playr.stopSave();
        stopSavePromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
    $("#ezopenStartTalk").on('click',function (){
        playr.startTalk();
    });
    $("#ezopenStopTalk").on('click',function (){
        playr.stopTalk();
    });
    $("#fullScreen").on('click',function (){
        var playPromise = playr.fullScreen();
        playPromise.then((data) => {
            console.log("promise 获取 数据", data)
        })
    });
});

function parseDefence(defence) {
    switch (Number(defence)) {
        case 0: return "睡眠|撤防";
        case 1: return "布防";
        case 8: return "在家";
        case 16: return "外出";
        default: return "未知";
    }
}

function parseOnOffStatus(status) {
    switch (Number(status)) {
        case 0: return "离线";
        case 1: return "在线";
        default: return "-";
    }
}
function parseStatus(status) {
    switch (Number(status)) {
        case 1: return "启用";
        case 2: return "禁用";
        default: return "-";
    }
}
function parseInstall(type) {
    switch (Number(type)) {
        case 1: return "楼栋";
        case 2: return "公共区域";
        default: return "-";
    }
}
function parseEncrypt(isEncrypt) {
    switch (Number(isEncrypt)) {
        case 0: return "不加密";
        case 1: return "加密";
        default: return "-";
    }
}

function parseFileType(fileType) {
    switch (Number(fileType)) {
        case 0: return "jpg";
        case 1: return "mp4";
        default: return "-";
    }
}
function parseStorageType(type) {
    switch (Number(type)) {
        case 1: return "标准存储";
        case 2: return "存档存储";
        default: return "-";
    }
}
function parseFileStatus(fileStatus) {
    switch (Number(fileStatus)) {
        case 0: return "正常";
        case 1: return "正在上传";
        case 2: return "上传失败";
        case 3: return "已过期";
        case 4: return "已删除";
        default: return "-";
    }
}
function parseQuality(videoLevel) {
    switch (Number(videoLevel)) {
        case 0: return "流畅";
        case 1: return "均衡";
        case 2: return "高清";
        case 3: return "超清";
        default: return "-";
    }
}
function parseShow(isAdd) {
    switch (Number(isAdd)) {
        case 0: return "隐藏";
        case 1: return "显示";
        default: return "-";
    }
}
function parseRelatedIpc(relatedIpc) {
    if(relatedIpc){
        return "是";
    }else {
        return "否";
    }
}
//预览大小根据原图的大小决定弹窗的大小
let imgDiv;
function previewImg(obj) {
    var img = new Image();
    img.src = obj.src;
    var height = img.height + 50; //获取图片高度
    var width = img.width; //获取图片宽度
    var imgHtml = "<img onclick='closeLayer()' src='" + obj.src + "' width='100%' height='100%'/>";
    //弹出层
    imgDiv = layui.layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
        area: ['100%', '100%'],
        shadeClose: true,
        scrollbar: false,
        title: "抓拍图片预览",
        content: imgHtml,
        cancel: function () {
        }
    });
}
function closeLayer() {
    if(imgDiv){
        layui.layer.close(imgDiv);
    }
}
function reload(){
    location.reload();
}
Date.prototype.format = function(fmt){
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };

    if(/(y+)/.test(fmt)){
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }

    for(var k in o){
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(
                RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }

    return fmt;
}